<?php
require_once "framework/config.php";

class Redirect
{
    var $queryString = '';

    function Redirect ( $queryString = '' )
    { 
        $this->queryString = $queryString;
    }
    
    function start()
    {
        if( !$this->isRedirect() )
        {
            return false;
        }
        
        $this->go();
        return false;
    }

    function go()
    {
        $options = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
        $url = '';

        if ( is_numeric( $this-> getGuideId() ) && !is_numeric( $this-> getSlideId() ) )
        {
            $url = $options['service_url']."?cmd=ShowRoute&id=".$this-> getGuideId();            
        }
        elseif( is_numeric( $this-> getGuideId() ) && is_numeric( $this-> getSlideId() ) )
        {
            $url = $options['service_url']."?cmd=ShowSlide&id=".$this-> getSlideId()."&guide_id=".$this-> getGuideId();
        }
        else
        {
            return false;
        }
        header("Location: ".$url);
        exit;
    }

    function isRedirect()
    {

        if ( $this->queryString == '' )
        {
            return false;
        }

        if( preg_match("/\d+|-\d+/i", $this->queryString) )
        {
            return true;
        }

        return false;
    }

    function getGuideId()
    {
        $array = split("-", $this->queryString );
        return $array[0];
    }

    function getSlideId()
    {
        $array = split("-", $this->queryString );
        return $array[1];
    }

}

$go = isset($_GET["go"]) ? $_GET["go"] : null;
$r = new Redirect( $go );
$r -> start();
?>
